package cn.zcy.springboot_servlet.config;

import cn.zcy.springboot_servlet.servlet.SpingBootBeanServlet;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.EventListener;
import java.util.LinkedList;
import java.util.List;

/**
 * 注册servlet
 */
@Configuration
public class MyWebMvcConfiguration {
    @Bean
    public ServletRegistrationBean myServlet() {
        //申明一个servlet注册器
        ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean();
        //设置servlet
        servletRegistrationBean.setServlet(new SpingBootBeanServlet());
        //设置名字
        servletRegistrationBean.setName("SpingBootBeanServlet");
        List<String> spingBootBeanServlet = new LinkedList<String>();
        //设置映射规则
        spingBootBeanServlet.add(("/spingBootBeanServlet"));
        servletRegistrationBean.setUrlMappings(spingBootBeanServlet);
//        servletRegistrationBean.addUrlMappings("/spingBootBeanServlet");
        return servletRegistrationBean;
    }

//    @Bean
//    public FilterRegistrationBean myFilter()
//    {
//        FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean();
////        filterRegistrationBean.setFilter();
//        filterRegistrationBean.addUrlPatterns();
//        return filterRegistrationBean;
//    }
//
//    public ServletListenerRegistrationBean myListener(){
//        ServletListenerRegistrationBean listenerRegistrationBean=new ServletListenerRegistrationBean();
//
////        listenerRegistrationBean.setListener();
//        EventListener listener = listenerRegistrationBean.getListener();
//        return listenerRegistrationBean;
//    }
}
